<template>
  <div id="Match_query" v-if="page_switch">
    <div class="Match_query_head">
      <el-input
        class="search_button"
        placeholder="请搜索关键词"
        v-model="search_content"
        @keyup.enter.native="search()"
      >
        <i
          slot="suffix"
          class="el-icon-search el-input__icon"
          @click="search"
          v-if="search_switch == true"
        ></i>
        <i
          slot="suffix"
          class="el-icon-close el-input__icon"
        
          @click="search_close"
          v-else
        ></i>
      </el-input>
      <div class="radio" style="margin: 13px 0px 0px 20px">
        排序：
        <el-radio-group @change="information_sort" v-model="bool">
          <el-radio v-model="bool" :label="true">倒序</el-radio>
          <el-radio v-model="bool" :label="false">正序</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="Match_query_up">
      <div
        class="Match_query_item"
        v-for="(item, index) in Match_query_item"
        :key="index"
        @click="to_Match_query_detailed(item.id)"
      >
        <span>{{ item.title }}</span>
        <span>{{ item.description }}</span>
        <img :src="item.coverPicture" alt="" />
        <span>{{ item.createTime }}</span>
      </div>
    </div>
    <el-pagination
      background
      class="Match_query_down"
      layout="prev, pager, next"
      :page-count="page_count"
      @current-change="handleCurrentChange"
      :current-page="page"
    >
    </el-pagination>
  </div>

  <div v-else class="Competition_information">
    <div class="Bread_crumbs">
      <span @click="page_switch = true">比赛查询&nbsp;</span>/
      <span>比赛详情</span>
    </div>
    <div class="Competition_content">
      <div class="Competition_content_up">
        <span>{{ match_content.title }} </span>
        <div class="Competition_time">
          <span> {{ match_content.commitName }}(作者)&nbsp;&nbsp;</span>
          <span class="el-icon-time">
            {{ match_content.competitionStartTime }}~</span
          >
          <span> {{ match_content.competitionEndTime }}</span>
          <!-- <span> {{ match_content.activityStartTime }}</span>
          <span> {{ match_content.activityEndTime }}</span> -->
        </div>
      </div>
      <p class="activity_detailed_text">
        {{ match_content.content }}
      </p>
      <div class="Reading_volume">
        <a :href="match_content.originalAddress"
          >阅读原文（点击查看比赛原文）</a
        >
        <a :href="match_content.applyAddress">点击报名</a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {},
  components: {},
  data() {
    return {
      page_switch: true,
      page: 1,
      page_count: 1,
      bool: true,
      Match_query_item: [],
      search_switch: true,
      search_content: "",
      match_content: "",
    };
  },
  methods: {
    search() {
      this.search_switch = false;
      this.page = 1;
      this.get_Match_query_information();
    },
    search_close() {
      this.search_content = "";
      this.search_switch = true;
      this.page = 1;
      this.get_Match_query_information();
    },
    information_sort() {
      this.get_Match_query_information();
    },
    async get_Match_query_information() {
      const self = this;
      const { data: res } = await this.$http({
        headers: { "Content-Type": "application/json;charset=UTF-8" },
        method: "get",
        url: "/api/team/getLecturesLike",
        params: {
          name: self.search_content,
          bool: self.bool,
          page: self.page,
          pageSize: 6,
        },
      });
      console.log(res);
      this.page_count = res.msg.pages;
      this.Match_query_item = res.msg.records;
    }, //监听页码值改变的事件
    handleCurrentChange(newSize) {
      this.page = newSize;
      this.get_Match_query_information();
    },
    async to_Match_query_detailed(id) {
      console.log(id);
      this.page_switch = false;
      const { data: res } = await this.$http({
        headers: { "Content-Type": "application/json;charset=UTF-8" },
        method: "get",
        url: "/api/team/getLectureById",
        params: {
          id: id,
        },
      });
      console.log(res);
      this.match_content = res.msg;
    },
  },
  created() {
    this.get_Match_query_information();  
  },
};
</script>

<style lang="less" >
#Match_query {
  width: 98%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.Match_query_head {
  height: 40px;
  display: flex;

  // justify-content: space-around;
  // background-color: rgb(216, 20, 20);
  .search_button {
    margin: 5px 0px 0px 20px;
    display: flex;
    height: 10px;
    width: 20%;

    i {
      color: blue;
      cursor: pointer;
    }
  }
}

.Match_query_up {
  height: 85%;
  // overflow: auto;
  width: 94%;
  margin: 10px auto;
  display: flex;

  flex-wrap: wrap;
  padding-left: 60px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 20px rgba(0, 0, 0, 0.04);
}
.Match_query_item {
  cursor: pointer;
  width: 30%;
  height: 40%;
  display: flex;
  flex-direction: column;
  justify-content: center;

  border: 1.5px solid rgb(82, 146, 192);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin: 20px 1%;

  span {
    width: 80%;
    margin: 3px auto;

    height: 10%;
    display: flex;
  }
  span:nth-child(1) {
    font-weight: bold;
    font-size: 25px;
  }
  span:nth-child(2) {
    font-size: 16px;
  }
  img {
    height: 63%;

    width: 80%;

    margin: 0px auto;
  }
}
.Match_query_down {
  // background-color: rgb(121, 14, 14);
  height: 40px;
  width: 97%;
  display: flex;
  justify-content: end;
}

//第二页
.Competition_information {
  display: flex;
  // background-color: rgb(201, 26, 26);
  width: 98%;
  height: 99%;
  flex-direction: column;

  //切换页面
  .Bread_crumbs {
    margin: 10px;
    span {
      cursor: pointer;
    }

    span:nth-child(1) {
      color: rgb(127, 127, 127);
    }
    span:nth-child(2) {
      color: rgb(0, 110, 255);
    }
    span:hover {
      color: rgb(0, 110, 255);
    }
  }
}
//正文
.Competition_content {
  height: 95%;
  width: 96%;
  margin: 20px 0 0 20px;
  display: flex;

  border-radius: 13px;
  // background: #ffffff;
  // background-color: rgb(126, 51, 51);
  box-shadow: 16px 16px 32px #919191, -16px -16px 32px #ffffff;
  flex-direction: column;
  overflow: auto;

  .Competition_content_up {
    display: flex;
    flex-direction: column;
    height: 100px;
    span {
      margin: 20px 0 10px 20px;
      //标题的字体大小
      font-size: 40px;
      font-weight: bold;
    }
    .Competition_time {
      height: 50px;
      line-height: 50px;
      color: grey;
      flex-direction: row;
      margin-left: 20px;
      border-bottom: 1px solid grey;
      span {
        font-weight: normal;
        margin: 0;
        font-size: 20px;
      }
    }
  }
}

.activity_detailed_text {
  font-weight: normal;
  width: 97%;
  margin: 20px auto;
  margin-top: 100px;
  font-size: 20px;
  word-wrap: break-word;
  word-break: break-all;
}
.Reading_volume {
  width: 97%;
  display: flex;
  justify-content: space-between;
  margin: 30px auto;
  flex-shrink: 0;
  height: 50px;

  line-height: 50px;
  border-top: 1px solid grey;

  a {
    color: rgb(98, 102, 235);
    text-decoration: none;
  }
}
.Competition_content::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: #fff;
}
.Competition_content::-webkit-scrollbar {
  width: 6px;
}
.Competition_content:hover::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
}
</style>